Skip to content

Should-BeAfter/BeBefore: make positional DateTime work#2709

Merged
nohwnd merged 1 commit into
pester:mainfrom
nohwnd:fix-time-positional
Jun 11, 2026
Merged

Should-BeAfter/BeBefore: make positional DateTime work#2709
nohwnd merged 1 commit into
pester:mainfrom
nohwnd:fix-time-positional

Conversation

@nohwnd

@nohwnd nohwnd commented Jun 11, 2026

Copy link
Copy Markdown
Member

The doc example

(Get-Date).AddDays(1) | Should-BeAfter (Get-Date)

errors today with Cannot bind positional parameters because no names were given. The Fluent and Expected parameter sets both declared a position-0 parameter ($Time and $Expected), so a DateTime at position 0 matched both sets and PowerShell could not pick one.

Split the Fluent parameter set into FluentAgo and FluentFromNow, each requiring its mandatory switch. With -Ago/-FromNow no longer optional within their set, neither fluent set is satisfiable from just a positional [DateTime], so the Expected set wins unambiguously.

Side effects:

  • Should-BeAfter 10minutes -Ago -FromNow now fails at binding ("parameter set cannot be resolved") instead of the runtime check.
  • The runtime "you must provide -Ago or -FromNow" guard is gone, since binding enforces it.

Added doc-style positional tests on both Should-BeAfter and Should-BeBefore. Verified the full Pester suite: 2171 passed, 0 failed.

Follow-up to #2707.

The doc example `(Get-Date).AddDays(1) | Should-BeAfter (Get-Date)`
errored with "Cannot bind positional parameters because no names were
given." The `Fluent` and `Expected` parameter sets both declared a
position-0 parameter (`$Time` and `$Expected`), so a `DateTime` at
position 0 matched both sets and PowerShell could not pick one.

Split the `Fluent` parameter set into `FluentAgo` and `FluentFromNow`,
each requiring its mandatory switch. With `-Ago`/`-FromNow` no longer
optional within their set, neither fluent set is satisfiable from just a
positional `[DateTime]`, so the `Expected` set wins unambiguously.

Side effects:
- `Should-BeAfter 10minutes -Ago -FromNow` now fails at binding (no
  parameter set can be resolved) instead of the runtime check.
- The runtime "you must provide -Ago or -FromNow" check is gone, since
  binding enforces it.

Added doc-style positional tests on both `Should-BeAfter` and
`Should-BeBefore`. Verified the full Pester suite: 2171 passed, 0
failed.

Follow-up to pester#2707.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd enabled auto-merge (squash) June 11, 2026 16:23
@nohwnd nohwnd merged commit 1375177 into pester:main Jun 11, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant